package com.grace.config;

import com.grace.interceptor.AdminInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Springboot配置类
 */
@Configuration
public class AppConfig implements WebMvcConfigurer {

    /**
     * 配置默认跳转
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //注册跳转页面为login
        registry.addViewController("/").setViewName("login");
        //跳转默认级别设置为最高
        //registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截类, 增加拦截路径, 增加放行路径
        registry.addInterceptor(new AdminInterceptor()).addPathPatterns("/**").excludePathPatterns("/","/user/login","/assets/**");
    }
}
